package com.duing.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class MailController {

    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${mail.smtp.emailAccount}")
    private String emailAccount;

    @Value("${mail.smtp.receiveAccount}")
    private String receiveAccount;

    @RequestMapping("/email")
    @ResponseBody
    public String sendEmail() {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(emailAccount);
        message.setTo(receiveAccount);

        message.setSubject("WZ 测试邮件");
        message.setText("成功收到一封来自WZ的邮件");

        javaMailSender.send(message);
        return "success";
    }
}
